package com.server.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author e4glet
 * 2025年3月5日
 * 数据库操作工具类
 * */

public class SQLHelper {
    public static Connection conn = DBUtils.Open();
    public static PreparedStatement pstmt;

    public static ResultSet ExecuteReader(String sqlString, Object[] param)
            throws SQLException
    {
        pstmt = conn.prepareStatement(sqlString);
        if (param != null)
        {
            for (int i = 0; i < param.length; i++)
            {
                pstmt.setObject(i + 1, param[i]);
            }
        }
        ResultSet rs = pstmt.executeQuery();
        return rs;
    }

    public static int ExecuteUpdate(String sqlString, Object[] param)
            throws SQLException
    {
        pstmt = conn.prepareStatement(sqlString);
        if (param != null)
        {
            for (int i = 0; i < param.length; i++)
            {
                pstmt.setObject(i + 1, param[i]);
            }
        }
        int i = pstmt.executeUpdate();
        return i;
    }
}
